import java.util.Stack;

public class test8 {
    public static void main(String[] args) {
        Node a = new Node(1);
        Node b = new Node(2);
        Node c = new Node(3);
        Node d = new Node(3);
        Node e = new Node(2);
        Node f = new Node(1);

        a.next = b;
        b.next = c;
        c.next = d;
        d.next = e;
        e.next = f;

        boolean result = getList(a);
        System.out.println(result);


        System.out.println("==========================================================");

    }

    public static boolean getList(Node head){
        if (head == null)
            return false;
        if(head.next==null)
            return true;

        // 先找到中心点,节点个数要区分偶数和奇数,直接使用栈,没到中心点就进栈,到中心点就出栈
        // 链表节点个数
        int length =0;
        Node cur = head;
        while (cur!=null){
            length++;
            cur = cur.next;
        }
        int mid = length/2;
        cur = head;
        Stack<Integer> stack = new Stack<>();
        while (mid>0){
            stack.push(cur.val);
            cur = cur.next;
            mid--;
        }
        // 也就是说中间点之前的已经全部被放入了栈内,这里就需要区分奇数偶数了
        if(length%2==0){
            //偶数
            while (!stack.isEmpty()){
                int flag = stack.pop();
                if (flag != cur.val)
                    return false;
                cur = cur.next;
            }
        }else {
            //奇数
            cur = cur.next;
            while (!stack.isEmpty()){
                int flag = stack.pop();
                if (flag != cur.val)
                    return false;
                cur = cur.next;
            }
        }
        return true;
    }
}
